package model.algorithm;

public abstract class State implements Comparable<State> {
	protected String state; 												// The state represented by a string
	protected double cost;  												// The cost to reach this state   (in some algo's = to gCost)
	protected State cameFrom;												 // The state we came from to this one.
	protected Action prevAct;												 // Last action that was in use and got to the current state
	
	
	public State(String state) {											// State C'tor - Gets a state string description and sets the string data member
		this.state = state;
	}
	
	public String getState() {												// String-state getter
		return this.state;
	}
	public void setState(String state) {									// String-state setter
		this.state = state;
	}
	public double getCost() {												// the state cost getter
		return cost;
	}
	public void setCost(double cost) {										// state cost setter
		this.cost = cost;
	}
	public State getCameFrom() {											// cameFrom getter - returns the parent state
		return cameFrom;
	}
	public void setCameFrom(State cameFrom) {								// cameFrom setter - sets the parent state
		this.cameFrom = cameFrom;
	}
	public Action getPrevAct() {											// prevAct getter - returns the last action
		return prevAct;
	}
	public void setPrevAct(Action prevAct) {								// prevAct setter - sets the last action
		this.prevAct = prevAct;
	}
	
	@Override
	public boolean equals(Object o){										// equals Override  - checks if the 2 states String description is equal
		return state.equals(((State) o).getState());
	}
	
	@Override
	public int compareTo(State state)										// compareTo Override - comparing between 2 states by their cost
	{
		if (this.getCost() > state.getCost())
			return 1;
		else if (this.getCost() < state.getCost())
			return -1;
		return 0;
	}

	
	@Override
	public String toString() {												// toString Override - returns the String description (state)
		return this.state;
	}

	@Override
	public int hashCode() {													// hashCode Override - uses the String hashCode func
		return this.state.hashCode();
	}
	
	
}